import requests


# 定义 类 --- 接口对象层
class EmpManagerApi(object):

    # 定义 方法 - 添加员工
    def add_emp(self, req_header, req_body):
        resp = requests.post(url="http://ihrm2-test.itheima.net/api/sys/user",
                             headers=req_header, json=req_body)
        return resp

    # 定义 方法 - 查询员工
    def query_emp(self, emp_id, req_header):
        resp = requests.get(url="http://ihrm2-test.itheima.net/api/sys/user/" + emp_id, headers=req_header)
        return resp

    # 定义 方法 - 修改员工
    def modify_emp(self, emp_id, req_header, req_body):
        resp = requests.put(url="http://ihrm2-test.itheima.net/api/sys/user/" + emp_id,
                            headers=req_header, json=req_body)
        return resp

    # 定义 方法 - 删除员工
    def del_emp(self, emp_id, req_header):
        return requests.delete(url="http://ihrm2-test.itheima.net/api/sys/user/" + emp_id, headers=req_header)


if __name__ == '__main__':
    # 创建实例
    emp = EmpManagerApi()

    # 准备请求头
    req_header = {"Authorization": "88428284-4837-47d7-98f4-6af0a6c402cf"}
    # 准备请求体
    # req_body = {
    #     "username": "user87655430",
    #     "mobile": "13947884780",
    #     "workNumber": "9527890aa"
    # }
    # # 用实例调用方法
    # resp = emp.add_emp(req_header, req_body)
    # print("添加员工：", resp.json())

    print("-" * 100)
    # 准备 员工id
    emp_id = "15808351987"
    resp = emp.query_emp(emp_id, req_header)
    print("查询员工：", resp.json())

    print("-" * 100)
    # 准备请求体
    mod_req_body = {"username": "至宗宝99"}
    resp = emp.modify_emp(emp_id, req_header, mod_req_body)
    print("修改员工：", resp.json())

    print("-" * 100)
    resp = emp.del_emp(emp_id, req_header)
    print("删除员工：", resp.json())
